home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / fractal / kaos.lha / binsrclib / kuntar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-18  |  1.5 KB  |  79 lines

  1. /* Unpack a single file packed by "sunpack" into a set of files whose names are provided by
  2. in-line keys at the biginning of each file */
  3. /* It read from standard input, output is automatically directed to
  4. the right directories with the properly assigned file names */
  5. /* Do not check for the existence or permission of files */
  6.  
  7. #include <stdio.h>
  8. #define FALSE 1
  9. #define TRUE 0
  10. #define LINE_LEN 240
  11.  
  12. main()
  13. {
  14.     int c,write_on;
  15.     char key[4],s[LINE_LEN],file[80];
  16.     FILE *fp,*fopen();
  17.     
  18.     write_on = FALSE;
  19.     while  ( ((int) getline(s,LINE_LEN)) != EOF) {
  20.         if(strncmp(s,"/*KTAR",6)==0){ 
  21.             if(strncmp(s,"/*KTAR NEWFILE",14)==0){
  22.                 get_file_name(file,s,15);
  23.                 fp=fopen(file,"w");
  24.                 if(fp==NULL){
  25.                     printf("File %s not found!\n",file);
  26.                     write_on = FALSE;
  27.                 }
  28.                 else
  29.                     write_on = TRUE;
  30.             }
  31.             else if(strncmp(s,"/*KTAR ENDFILE",14)==0){
  32.                 fclose(fp);
  33.                 write_on = FALSE;
  34.             }    
  35.             else {
  36.                 if(write_on == TRUE)
  37.                     fputs(s,fp);
  38.             }
  39.         }
  40.         else {
  41.             if(write_on == TRUE)
  42.                 fputs(s,fp);
  43.         }
  44.     }
  45. }
  46.  
  47. /* get file name starting starting at n'th character of s until white space */
  48. get_file_name(t,s,n)
  49. char t[],s[];
  50. int n;
  51. {
  52.     int i =0;
  53.         
  54.     while (s[n] != ' ' && s[n] != '\n' && s[n] != '\t' && s[n] != '\0')
  55.         t[i++] = s[n++];
  56.     t[i]='\0';
  57. }
  58.  
  59. /* get line into s, return length */
  60.  
  61. int
  62. getline(s,length)  
  63. char s[];
  64. int length;
  65. {
  66.     int c,i;
  67.  
  68.     i = 0;
  69.     while (--length > 0 && (c=getchar()) != EOF && c != '\n')
  70.         s[i++] = c;
  71.     if( c == '\n')
  72.         s[i++] = c;
  73.     s[i] = '\0';
  74.     if(c == EOF)
  75.         return(c);
  76.     else
  77.         return(i);
  78. }
  79.